package com.fr.chart.core.glyph;

import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ColorInfo;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.math.Plot3D;
import com.fr.chart.math.Projection;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.shape3d.FoldLine3D;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

public class Line3DPlotGlyph extends CategoryPlotGlyph
  implements Plot3D
{
  private static final long serialVersionUID = 8357789096646931867L;
  public static final String XML_TAG = "Line3DPlotGlyph";
  private double seriesIntervalPercent = 0.0D;
  private int deep = -1;
  private Projection projection = new Projection();

  public void layoutAxisGlyph()
  {
    super.layoutAxisGlyph();
    layout3DAxisGlyph();
  }

  public void layoutDataSeriesGlyph()
  {
    if (this.deep == -1)
      this.deep = (int)getBounds().getWidth();
    int i = getSeriesSize();
    double d1 = this.deep / (1.0D + getSeriesIntervalPercent()) * i;
    for (int j = i - 1; j >= 0; --j)
    {
      DataSeries localDataSeries = getSeries(j);
      double d2 = -getSeriesIntervalPercent() * d1 * (0.5D + j) - d1 * j;
      FoldLine3D localFoldLine3D = new FoldLine3D(0.0F, 100.0F);
      localDataSeries.setDrawImpl(localFoldLine3D);
      localFoldLine3D.setProjection(this.projection);
      localFoldLine3D.getColorInfo().dealCondition(getSeriesCollection(), j);
      for (int k = 0; k < localDataSeries.getDataPointCount(); ++k)
      {
        float f2;
        DataPoint localDataPoint = localDataSeries.getDataPoint(k);
        double d3 = getDataPointPercentValue(j, k);
        float f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(k, 0.5D).getX();
        if (isStacked())
        {
          double d4 = 0.0D;
          for (int l = j - 1; l >= 0; --l)
            d4 += getDataPointPercentValue(l, k);
          f2 = (float)(getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d4 + d3).getY());
        }
        else
        {
          f2 = (float)(getValueAxisGlyph().getBounds().getY() + (float)getValueAxisGlyph().getPoint2D(d3).getY());
        }
        if (k == 0)
          localFoldLine3D.moveTo(f1, f2);
        else
          localFoldLine3D.lineTo(f1, f2);
        Point2D localPoint2D = this.projection.projectee(f1, f2, 0.0D);
        localDataPoint.setShape(new Arc2D.Double(localPoint2D.getX() - 3.0D, localPoint2D.getY() - 3.0D, 6.0D, 6.0D, 0.0D, 360.0D, 2));
        dealDataPointLabelBounds(localDataPoint, j);
      }
    }
  }

  public int getDeep()
  {
    return this.deep;
  }

  public void setDeep(int paramInt)
  {
    this.deep = paramInt;
  }

  public Projection getProjection()
  {
    return this.projection;
  }

  public void setProjection(Projection paramProjection)
  {
    this.projection = paramProjection;
  }

  public void setSeriesIntervalPercent(double paramDouble)
  {
    this.seriesIntervalPercent = paramDouble;
  }

  public double getSeriesIntervalPercent()
  {
    return this.seriesIntervalPercent;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Line3DPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("deep", this.deep).attr("seriesIntervalPercent", this.seriesIntervalPercent).end();
    if (this.projection != null)
      this.projection.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("deep")) != null)
          this.deep = Integer.valueOf(str2).intValue();
        if ((str2 = paramXMLableReader.getAttr("seriesIntervalPercent")) != null)
          this.seriesIntervalPercent = Double.valueOf(str2).doubleValue();
      }
      else if (str1.equals("Projection"))
      {
        this.projection = ((Projection)paramXMLableReader.readXMLObject(new Projection()));
      }
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof Line3DPlotGlyph))
      return false;
    Line3DPlotGlyph localLine3DPlotGlyph = (Line3DPlotGlyph)paramObject;
    if (!(super.equals(localLine3DPlotGlyph)))
      return false;
    if (localLine3DPlotGlyph.deep != this.deep)
      return false;
    if (localLine3DPlotGlyph.seriesIntervalPercent != this.seriesIntervalPercent)
      return false;
    return (Equals.equals(localLine3DPlotGlyph.projection, this.projection));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    Line3DPlotGlyph localLine3DPlotGlyph = (Line3DPlotGlyph)super.clone();
    if (this.projection != null)
      localLine3DPlotGlyph.projection = ((Projection)this.projection.clone());
    return localLine3DPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("deep", this.deep);
    localJSONObject.put("projection", this.projection.toJSONObject());
    localJSONObject.put("seriesIntervalPercent", this.seriesIntervalPercent);
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "Line3DPlotGlyph";
  }
}